<template>
	<view class="container">
		<swiper class="swiper-container" indicator-dots indicator-color="#fff" autoplay interval="3000" circular>
			<block v-for="(item,index) in swImage" :key="index">
				<swiper-item>
					<view class="item">
						<image :src="item.image" mode="aspectFill"></image>
					</view>
				</swiper-item>
			</block>
		</swiper>

		<view class="xqmsg">
			<view class="xq_message">
				<view class="qian">
					￥{{xqtxt.price}}
				</view>
				<view class="taocan">
					{{xqtxt.storeName}}
				</view>
				<view class="jiage">
					<view class="yuan">原价：￥{{xqtxt.otPrice}}</view>
					<view class="yuan">库存：￥{{xqtxt.stock}}个</view>
					<view class="yuan">销量：{{xqtxt.sales}}个</view>
				</view>
			</view>
		</view>

		<!-- <view class="evaluate">
			<view class="moren">
				<view class="moren_c">
					<view class="moren_l">
						<view class="yxz">已选择：</view>
						<view class="mr">默认</view>
					</view>

					<view class="moren_r">
						<image src="/static/image/shop/14.png" mode=""></image>
					</view>
				</view>
			</view>

			<view class="moren">
				<view class="moren_c">
					<view class="moren_l user_pj">
						<view>用户评价</view>
						<view>（0）</view>
					</view>

					<view class="moren_r user_r">
						<view class="mr">
							<view class="pj">好评</view>
							<view class="pj2">100%</view>
						</view>
						<view>
							<image src="/static/image/shop/14.png" mode=""></image>
						</view>
					</view>
				</view>
			</view>
		</view> -->

		<view class="cpxq">
			<view class="cp">产品详情</view>
			<view class="cpimg">
				<image :src="xqImage" mode=""></image>
			</view>
		</view>

		<view class="bottom">
			<view class="centent">
				<view class="btm_l">
					<view class="kefu">
						<image src="/static/image/shop/7.png" mode=""></image>
						<view class="kftxt">客服</view>
					</view>
					<view class="kefu" @click="scBtn" v-if="favorite === false">
						<image src="/static/image/shop/8.png" mode=""></image>
						<view class="kftxt">收藏</view>
					</view>
					<view class="kefu" @click="scBtn" v-else-if="favorite === true">
						<image src="/static/image/shop/8-1.png" mode=""></image>
						<view class="kftxt">收藏</view>
					</view>
				</view>
				<view class="btm_buy" @click="nowBuy">
					<button class="buy">立即购买</button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import $http from "@/ajax/http.js"
	export default {
		data() {
			return {
				// token
				token: wx.getStorageSync('shopToken'),
				ids: '',
				xqtxt: '',
				swImage: '',
				xqImage: '',
				// 是否已收藏
				favorite: false,
			}
		},
		onLoad(options) {
			this.ids = options.id
			console.log(options, "options");
			this.initXq();
		},

		methods: {
			initXq() {
				$http.request({
					header: {
						"Authori-zation": this.token
					},
					url: `/api/front/product/detail/${this.ids}`
				}, 2).then((res) => {
					console.log(res, "详情页面");
					this.xqtxt = res.productInfo
					this.swImage = res.productValue
					this.xqImage = res.productInfo.content
					this.favorite = res.userCollect
				})

			},

			// 收藏按钮
			scBtn() {
				if (this.favorite === false) {
					$http.request({
						header: {
							"Authori-zation": this.token
						},
						url: '/api/front/collect/add',
						data: {
							"category": "store",
							"id": this.ids
						},
						method: 'POST'
					}, 2).then((res) => {
						if (res.code == 200) {
							this.favorite = true
						} else {
							wx.showToast({
								title: '收藏失败',
								icon: 'none'
							})
						}
					})

				} else if (this.favorite === true) {
					const proId = this.ids
					$http.request({
						header: {
							"Authori-zation": this.token
						},
						url: `/api/front/collect/cancel/${proId}`,
						method: 'POST'
					}, 2).then((res) => {
						if (res.code === 200) {
							this.favorite = false
						} else {
							wx.showToast({
								title: '取消收藏失败',
								icon: 'none'
							})
						}
					})
				}

			},

			// 立即购买
			nowBuy() {

				$http.request({
					header: {
						"Authori-zation": this.token
					},
					url: '/api/front/address/default',
				}, 2).then((res) => {
					console.log(res, "获取默认地址");
					if (res.code === 200 && res.data === null) {
						wx.showModal({
							content: '您还未设置收货地址哦，赶快设置一个吧',
							success(res) {
								if (res.confirm) {
									wx.navigateTo({
										url: '/pages/shop/address/index'
									});
								} else if (res.cancel) {
									console.log('用户点击取消');
								}
							}
						})
					} else {
						const id = this.ids
						wx.navigateTo({
							url: `/pages/shop/nowBuy/index?id=${id}`
						})
					}
				})
				// const id = this.ids

				// uni.navigateTo({
				// 	url: `/pages/shop/nowBuy/index?id=${id}`
				// })
			}
		}
	}
</script>

<style scoped lang="scss">
	.container {
		width: 100%;
		background-color: #f5f5f5;
		display: flex;
		align-items: center;
		flex-direction: column;

		.swiper-container {
			width: 750rpx;
			height: 600rpx;
		}

		.item {
			height: 600rpx;
		}

		.item image {
			width: 750rpx;
			height: 100%;
		}

		.xqmsg {
			display: flex;
			align-items: center;
			justify-content: center;
			flex-direction: column;
			background-color: #ffffff;
			width: 696rpx;

			.xq_message {
				display: flex;
				flex-direction: column;
				justify-content: space-between;
				width: 636rpx;

				.qian {
					font-weight: 500;
					font-size: 47rpx;
					color: #DB1E00;
					margin-top: 20rpx;
				}

				.taocan {
					font-weight: 400;
					font-size: 32rpx;
					color: #1A1A1A;
					margin-top: 10rpx;
				}

				.jiage {
					margin-top: 20rpx;
					margin-bottom: 20rpx;
					display: flex;
					flex-direction: row;
					justify-content: space-between;
					font-weight: 400;
					font-size: 23rpx;
					color: #84838A;
				}


			}
		}

		.evaluate {
			width: 696rpx;
			height: 187rpx;
			display: flex;
			flex-direction: column;
			justify-content: space-between;
			margin-top: 29rpx;

			.moren {
				display: flex;
				flex-direction: row;
				align-items: center;
				justify-content: center;
				width: 696rpx;
				height: 80rpx;
				background-color: #ffffff;
				border-radius: 20rpx;
				margin-bottom: 25rpx;

				.moren_c {
					display: flex;
					flex-direction: row;
					justify-content: space-between;
					width: 644rpx;

					.moren_l {
						display: flex;
						flex-direction: row;
						align-items: center;
						font-weight: 400;
						font-size: 26rpx;

						.yxz {
							color: #84838A;
						}

						.mr {
							color: #1A1A1A;
						}
					}

					.user_pj {
						font-weight: 400;
						font-size: 26rpx;
						color: #84838A;
					}

					.moren_r {
						image {
							width: 20rpx;
							height: 23rpx;
						}
					}

					.user_r {
						width: 150rpx;
						display: flex;
						flex-direction: row;
						justify-content: space-between;

						.mr {
							display: flex;
							flex-direction: row;
							align-items: center;
							font-weight: 400;
							font-size: 26rpx;
							color: #84838A;

							.pj2 {
								color: #DB1E00;
							}
						}
					}
				}


			}
		}

		.cpxq {
			width: 694rpx;
			margin-top: 38rpx;
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
			font-weight: 400;
			font-size: 32rpx;
			color: #333333;

			.cp {
				margin-bottom: 26rpx;
			}

			.cpimg {
				width: 696rpx;

				image {
					width: 696rpx;
				}
			}
		}


		.bottom {
			display: flex;
			justify-content: center;
			align-items: center;
			position: fixed;
			bottom: 0;
			width: 100%;
			height: 154rpx;
			background-color: #ffffff;

			.centent {
				width: 640rpx;
				display: flex;
				justify-content: space-between;

				.btm_l {
					width: 116rpx;
					display: flex;
					flex-direction: row;
					align-items: center;
					justify-content: space-between;

					.kefu {
						display: flex;
						flex-direction: column;

						image {
							width: 34rpx;
							height: 33rpx;
						}

						.kftxt {
							font-weight: 400;
							font-size: 18rpx;
							color: #595757;
							margin-top: 8rpx;
						}

					}
				}

				.btm_buy {
					width: 239rpx;
					height: 69rpx;

					.buy {
						width: 239rpx;
						height: 69rpx;
						line-height: 69rpx;
						border-radius: 45rpx;
						font-weight: 400;
						font-size: 30rpx;
						color: #FFFFFF;
						background: linear-gradient(to right top, rgba(37, 188, 169, 1), rgba(0, 130, 139, 1));
					}
				}
			}





		}
	}
</style>